$(function(){
	//分类
	var activitySwiper = new Swiper('.activity-swiper', {
			freeMode : true,
			slidesPerView:'4',
		});
	//点击切换一级分类
	$(".horizontal-swiper").on("click","a",function(){
		
		var _this = $(this);
		$(this).parents("ul").each(function(){
			$(this).find(".active").removeClass("active");
			_this.find("span").addClass("active");
		});
		
		$(".type-list").html('<div class="loading middle">'
				+'<img src="http://oaats41rf.bkt.clouddn.com/loading.gif"/>加载中...'
			+'</div>');
		var oneProductCategoryId = _this.attr("data-id");
		var oneProductCategoryUrl = _this.attr("data-url");
		$.ajax({
			type:"get",
			url:base_url+"customer/getClassifyMsgByOneId",
			data:{"oneProductCategoryId":oneProductCategoryId},
			success:function(data){
				var html ="";
				for(var i=0;i<data.length;i++){
					var threeProductCategories = data[i].threeProductCategories;
					html = html
					+ '<div class="second-type">'
					+ '<div class="second-type-title f16">'
					+ data[i].twoProductCategory.productCategoryName
					+ '</div>'
					+'<ul class="three-type-list clearfloat">';
					for(var j=0;j<threeProductCategories.length;j++){
						html = html
							+'<li>'
							+'<a>'
							+'<span class="img-wrap">'
							+'<img src="'+threeProductCategories[j].productCategoryUrl+'" name="threeProductCategory"  data-id="'+threeProductCategories[j].productCategoryId+'" data-name="'+threeProductCategories[j].productCategoryName+'" />'
							+'</span>'
							+'<span class="three-type-name">'+threeProductCategories[j].productCategoryName+'</span>'
							+'</a>'
							+'</li>';
					}
					html = html + '</ul></div>';
				}
				$(".type-list").hide().html(html);
				$(".type-list").fadeIn();
			},
			error:function(){
			}
		});
	});

	//点击三级分类跳到商品展示
	$('.type-list').on("click",'span[class="img-wrap"]',function(){
		var threeCategoryId = $(this).find("img").attr("data-id");
		var threeCategoryName = $(this).find("img").attr("data-name");
		var json = {
				"threeCategoryId":threeCategoryId,
				"threeCategoryName":threeCategoryName
		}
		var jsonStr = JSON.stringify(json);
		window.location.href = base_url + "customer/getPlatformClassifyProductMsges?jsonStr="+jsonStr;
	});

});
